Skip to content

Conversation

@seefeldb
Copy link
Contributor

@seefeldb seefeldb commented Oct 31, 2025

Problem

The @commontools/memory and @commontools/runner packages had a circular dependency:

  • memory/interface.ts imported JSONValue, SchemaContext, and SchemaPathSelector from @commontools/runner
  • runner extensively imports from @commontools/memory/interface

This circular dependency caused:

  • Every file in runner to pull in 267 dependencies (34.55MB) during typechecking
  • Even simple 50-line utility files took 0.5s to typecheck instead of 0.013s
  • Slow language server performance when editing runner files

Solution

Moved two simple type definitions from runner to memory:

  1. SchemaContext - wraps two JSONSchema fields
  2. SchemaPathSelector - wraps path + optional SchemaContext

These types conceptually belong in memory as they're used in memory's query interface (SchemaSelector).

Changes

  • packages/memory/interface.ts: Define SchemaContext and SchemaPathSelector locally, import JSONSchema from @commontools/api instead of runner
  • packages/runner/src/builder/types.ts: Import SchemaContext from memory
  • packages/runner/src/traverse.ts: Import SchemaContext and SchemaPathSelector from memory

Impact

Performance Improvements

  • Simple utility files now compile 30-40x faster (0.013s vs 0.5s)
  • Dependency reduction: Simple files went from 267 dependencies (34MB) to 2-5 dependencies (~116KB)
  • Total typecheck time: Reduced by 3 seconds for runner package (104s → 101s)

Before vs After

cancel.ts (simple utility):

  • Before: 267 dependencies, 34.55MB
  • After: 2 dependencies, 116.5KB
  • Speedup: 36x faster typecheck

memory/interface.ts:

  • Before: Imported from @commontools/runner → circular dependency
  • After: Only imports from merkle-reference and @commontools/api → no circle ✅

Testing

All packages typecheck successfully:

deno check --all packages/runner/src/index.ts   #
deno check --all packages/memory/interface.ts   #
deno check --all packages/api/index.ts          #

🤖 Generated with Claude Code


Summary by cubic

Broke the circular dependency between @commontools/memory and @commontools/runner by moving SchemaContext and SchemaPathSelector to memory. This cuts typecheck overhead and speeds up runner builds.

  • Refactors

    • Define SchemaContext and SchemaPathSelector in memory/interface.ts.
    • Import JSONSchema from @commontools/api in memory; remove runner imports.
    • Update runner builder/types.ts and traverse.ts to import these types from memory.
  • Performance

    • Simple runner files compile ~30–40x faster (0.013s vs 0.5s).
    • Dependencies per simple file drop from 267 (~34MB) to 2–5 (~116KB).
    • Runner typecheck time reduced by ~3s (104s → 101s).

Written for commit 2a8c720. Summary will update automatically on new commits.

Move SchemaContext and SchemaPathSelector type definitions from runner
to memory/interface.ts, eliminating the circular import between packages.

Changes:
- memory/interface.ts: Define SchemaContext and SchemaPathSelector locally,
  import JSONSchema from @commontools/api instead of @commontools/runner
- runner/src/builder/types.ts: Import SchemaContext from memory
- runner/src/traverse.ts: Import SchemaContext and SchemaPathSelector from memory

Impact:
- Files without complex runner dependencies now compile 30-40x faster
  (0.013s vs 0.5s)
- Simple utility files reduced from 267 dependencies (34MB) to 2-5
  dependencies (~116KB)
- Total runner package typecheck time reduced by 3 seconds

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@seefeldb seefeldb requested a review from ubik2 October 31, 2025 18:25
@seefeldb
Copy link
Contributor Author

Not a massive difference in the end, but also doesn't hurt.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

@seefeldb seefeldb merged commit ac34e82 into main Oct 31, 2025
9 checks passed
@seefeldb seefeldb deleted the berni/remove-circular-dependency-between-runner-and-memory branch October 31, 2025 18:43
jkomoros pushed a commit that referenced this pull request Nov 2, 2025
Break circular dependency between memory and runner

Move SchemaContext and SchemaPathSelector type definitions from runner
to memory/interface.ts, eliminating the circular import between packages.

Changes:
- memory/interface.ts: Define SchemaContext and SchemaPathSelector locally,
  import JSONSchema from @commontools/api instead of @commontools/runner
- runner/src/builder/types.ts: Import SchemaContext from memory
- runner/src/traverse.ts: Import SchemaContext and SchemaPathSelector from memory

Impact:
- Files without complex runner dependencies now compile 30-40x faster
  (0.013s vs 0.5s)
- Simple utility files reduced from 267 dependencies (34MB) to 2-5
  dependencies (~116KB)
- Total runner package typecheck time reduced by 3 seconds

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
Copy link
Contributor

@ubik2 ubik2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants